package com.example.service.impl;

import com.example.mapper.GoodTypeMapper;
import com.example.pojo.Brand;
import com.example.pojo.GoodType;
import com.example.pojo.PageBean;
import com.example.service.GoodService;
import com.example.service.GoodTypeService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodTypeImpl implements GoodTypeService {
    @Autowired
    private GoodTypeMapper goodTypeMapper;

    @Override
    public PageBean getGoodType(GoodType goodType, Integer page, Integer pageSize) {
        //设置分页参数
        PageHelper.startPage(page,pageSize);
        List<GoodType> list = goodTypeMapper.getGoodType(goodType);
        Page<GoodType> p= (Page<GoodType>) list;
        PageBean pageBean=new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }

    @Override
    public void addGoodType(GoodType goodType) {
        goodTypeMapper.addGoodType(goodType);
    }

    @Override
    public void changeGoodType(GoodType goodType) {
        goodTypeMapper.changeGoodType(goodType);
    }

    @Override
    public Integer deleteGoodType(String id) {
        if(goodTypeMapper.findLastType(id)==0)
            return goodTypeMapper.deleteGoodType(id);
        else
            return 0;
    }

    @Override
    public List<GoodType> getGoodTypeList() {
        return goodTypeMapper.getGoodTypeList();
    }
}
